<template>
<div>
  <Table border :columns="columns12" :data="data">
    <template slot-scope="{ row }" slot="name">
      <strong>{{ row.name }}</strong>
    </template>
    <template slot-scope="{ row, index }" slot="action">
      <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">借阅</Button>
    </template>
  </Table>
</div>
</template>

<script>
export default {
  name: "booklist",
  data () {
    return {
      addBook:false,
      UpdateBook:false,
      columns12: [
        {
          title: '书名称',
          slot: 'name'
        },
        {
          title: '书名称',
          key: 'author'
        },
        {
          title: '出版社',
          key: 'publish'
        },
        {
          title: '标准书号',
          key: 'isbn'
        },
        {
          title: '书介绍',
          key: 'introduction'
        },
        {
          title: '语言',
          key: 'language'
        },
        {
          title: '价格信息',
          key: 'price'
        },
        {
          title: '出版时间',
          key: 'pub_date'
        },
        {
          title: '图书类型',
          key: 'type_id'
        },
        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ],
      data: []
    }
  },
  methods: {
    show (row) {
      this.$confirm("是否借阅？","提示").then (()=>{
        let data={
          bookid:row.id,
          readerid:this.getUser.id,
          type: "未归还",
          giveback:'2'
        }
        console.log(this.data)
        this.http.post("/setBorrow",this.qs.parse(data)).then(res=>{
          if (res.data){
            this.$message.success('成功')
          }else{
            this.$message.error('失败')          }
        })
      })
    },
    getInformation(){
      this.http.post("get").then(res=>{
        if (res.data){
          console.log(res.data)
          this.data=res.data
        }
      })
    }
  },
  created() {
    this.getInformation();
  },
  computed:{
    getUser(){
      return this.$store.state.user
    }
  }
}
</script>

<style scoped>

</style>
